package org.kms.Controllers;

import org.kms.dao.manageDao;
import org.kms.pojo.Manage;
import org.kms.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/Manage")
@CrossOrigin(value = "*")
public class manage {
    @Autowired
    private manageDao manageDao;
    @RequestMapping("/manageIndex")
    @ResponseBody
    public ResponseResult<List<Manage>> manageGetall(Integer glId)throws Exception{
        return new ResponseResult<>(manageDao.getbymanage(glId));
    }
    @RequestMapping("/manage2")
    @ResponseBody
    public List<Manage> manageall(Integer gradeId,Integer glId)throws Exception{
        return manageDao.getbygradeIddata(glId,gradeId);
    }

    @RequestMapping("/manageAdd")
    @ResponseBody
    public ResponseResult manageAdd(Manage manage) throws Exception{
        manageDao.add(manage);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/manageUpdate")
    @ResponseBody
    public ResponseResult manageUpdate(Manage manage ,Integer gradeId) throws Exception{
        manageDao.update(manage);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/manageDelete")
    @ResponseBody
    public ResponseResult manageDelete(Integer cmId) throws Exception{
        manageDao.delete(cmId);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/manageAndChildAll")
    @ResponseBody
    public ResponseResult<List<Manage>> getChilds(Integer glId) throws Exception{
        List<Manage> manageAndChildAll = manageDao.getChildbyManageAll(glId);
        return new ResponseResult<>(manageAndChildAll);
    }
}
